﻿using System;
using System.Collections.Generic;
using System.Text;

namespace DBUtil.FastEntity.Annotations
{
    #region Ignore
    [AttributeUsage(AttributeTargets.Property)]
    public class IgnoreUpdateAttribute : Attribute { }
    [AttributeUsage(AttributeTargets.Property)]
    public class IgnoreSelectAttribute : Attribute { }
    [AttributeUsage(AttributeTargets.Property)]
    public class IgnoreInsertAttribute : Attribute { }
    [AttributeUsage(AttributeTargets.Property)]
    public class IgnoreWriteAttribute : Attribute { }
    #endregion

    #region RawString
    [AttributeUsage(AttributeTargets.Property)]
    public class RawStringAttribute : Attribute { }
    #endregion

    #region PrimaryKey
    [AttributeUsage(AttributeTargets.Property)]
    public class PrimaryKeyAttribute : Attribute
    {
        /// <summary>
        /// 主键生成策略,默认: 自定义
        /// </summary>
        public KeyStrategy KeyStrategy { get; set; } = KeyStrategy.Custom;

        public object Arg { get; set; }
    }

    public enum KeyStrategy
    {
        /// <summary>
        /// 自定义，插入时必须手动指定值，默认
        /// </summary>
        Custom,
        /// <summary>
        /// 自定义生成器类,在Arg补充Type值，如：<code>[PrimaryKey(KeyStrategy=KeyStrategy.CustomGenerator,Arg=typeof(MyGenerator))]</code>
        /// 其中，MyGenerator 需要实现 <seealso cref="IEntityIdGenerator"/> 接口
        /// </summary>
        CustomGenerator,
        /// <summary>
        /// 自增
        /// <list type="number">
        /// <item>sqlserver：identity(1,1)</item>
        /// <item>mysql：auto_increment</item>
        /// </list>
        /// </summary>
        Identity,
        /// <summary>
        /// db.NewId
        /// </summary>
        NewId,
        /// <summary>
        /// 序列
        /// </summary>
        Sequence,
        /// <summary>
        /// Guid
        /// </summary>
        Guid
    }
    #endregion

    #region Refer
    [AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
    public class ReferHitAttribute : Attribute
    {
        public string ReferName { get; set; }
        public EnumReferHitType ReferHitType { get; set; } = EnumReferHitType.Direct;
        public string SplitString { get; set; }

        public Type ReferTable { get; set; }
        public string ReferProp { get; set; }
        public string StaticReferProp1 { get; set; }
        public object StaticReferValue1 { get; set; }
        public string StaticReferProp2 { get; set; }
        public object StaticReferValue2 { get; set; }
        public string StaticReferProp3 { get; set; }
        public object StaticReferValue3 { get; set; }

        public object StaticThisValue { get; set; }
    }

    public enum EnumReferHitType
    {
        Direct = 1,
        Split = 2
    }

    [AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
    public class UseReferHitTableAttribute : Attribute
    {
        public Type HitTable { get; set; }
    }

    [AttributeUsage(AttributeTargets.Property)]
    public class ReferColumnAttribute : Attribute
    {
        public string ReferHint { get; set; }
        public string ReferProp { get; set; }
    }

    [AttributeUsage(AttributeTargets.Property)]
    public class ReferTableAttribute : Attribute
    {
        public string ReferHint { get; set; }
    }
    #endregion

    #region Tree

    public enum EnumTableTreeType
    {
        ParentId = 1,
        HierarchyId = 2,
        IdSegment = 3
    }

    [AttributeUsage(AttributeTargets.Class)]
    public class TableTreeAttribute : Attribute
    {
        public EnumTableTreeType TreeType { get; set; }
    }

    [AttributeUsage(AttributeTargets.Property)]
    public class TableTreeIdAttribute : Attribute { }
    [AttributeUsage(AttributeTargets.Property)]
    public class TableTreeParentIdAttribute : Attribute { }
    [AttributeUsage(AttributeTargets.Property)]
    public class TableTreeChildrenAttribute : Attribute { }
    [AttributeUsage(AttributeTargets.Property)]
    public class TableTreeIdSegmentAttribute : Attribute
    {
        public string SplitChar { get; set; }
    }
    #endregion

    #region Audit
    [AttributeUsage(AttributeTargets.Property)]
    public class AuditCreateTimeAttribute : Attribute { }
    [AttributeUsage(AttributeTargets.Property)]
    public class AuditCreateUserIdAttribute : Attribute
    {
        /// <summary>
        /// 当未获取到用户id时的取值
        /// </summary>
        public object Default { get; set; }
    }
    [AttributeUsage(AttributeTargets.Property)]
    public class AuditUpdateTimeAttribute : Attribute
    {
        /// <summary>
        /// 是否初始值设定取 AuditCreateTimeAttribute
        /// </summary>
        public bool InitUseCreateValue { get; set; } = true;
    }
    [AttributeUsage(AttributeTargets.Property)]
    public class AuditUpdateUserIdAttribute : Attribute
    {
        /// <summary>
        /// 当未获取到用户id时的取值
        /// </summary>
        public object Default { get; set; }
        /// <summary>
        /// 是否初始值设定取 AuditCreateTimeAttribute
        /// </summary>
        public bool InitUseCreateValue { get; set; } = true;
    }
    [AttributeUsage(AttributeTargets.Property)]
    public class AuditDeleteTimeAttribute : Attribute { }
    [AttributeUsage(AttributeTargets.Property)]
    public class AuditDeleteUserIdAttribute : Attribute
    {
        /// <summary>
        /// 当未获取到用户id时的取值
        /// </summary>
        public object Default { get; set; }
    }
    #endregion

    #region StoreJson

    [AttributeUsage(AttributeTargets.Property)]
    public class StoreJsonFastAttribute : Attribute
    {
        public string DateFormatString { get; set; } = "yyyy-MM-dd HH:mm:ss";
        public bool IsLongToString { get; set; } = false;
        public bool IgnoreNull { get; set; } = false;
        public bool Enum2String { get; set; } = true;
        public bool LowerCamelCase { get; set; } = false;
        public bool IsIntend { get; set; } = false;
        public bool IsAllToString { get; set; } = false;
        public int? AllNumDigit { get; set; } = null;
        public int? DecimalDigit { get; set; } = null;
    }

    [AttributeUsage(AttributeTargets.Property)]
    public class StoreJsonAttribute : Attribute
    {
    }

    #endregion
}
